
/**
 * 是否為url格式
 * 
 * @returns {Boolean}
 */
String.prototype.isUrl = function () {
   var strRegex = "^((https|http|ftp|rtsp|mms)?://)";/*
														 * +
														 * "?(([0-9a-z_!~*'().&=+$%-]+:
														 * )?[0-9a-z_!~*'().&=+$%-]+@)?" +
														 * "(([0-9]{1,3}\.){3}[0-9]{1,3}" +
														 * "|" +
														 * "([0-9a-z_!~*'()-]+\.)*" +
														 * "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." +
														 * "[a-z]{2,6})" +
														 * "(:[0-9]{1,4})?" +
														 * "((/?)|" +
														 * "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
														 */ 
	var re = new RegExp(strRegex); 
	return re.test(this); 
};


String.prototype.formatNumber = function () {
	/*
	 * if(isNaN(this)) { return ''; } if(this == 0) { return this; } var
	 * re=/^(-?)(\d+)/,x,y;
	 * 
	 * if(x=re.exec(this)){ for (var a=x[2].split(''),i=a.length-3;i>0;i-=3)
	 * {a.splice(i,0,',');}; this=this.replace(re,x[1]+a.join('')); }
	 */
    return this;
};

/**
 * 是否為Email格式
 * 
 * @returns {Boolean}
 */
String.prototype.isEmail = function() {
  var strr;
  var mail = this.replace("-","");
  
  var re = /(\w+@\w+\.\w+)(\.{0,1}\w*)(\.{0,1}\w*)/i;
  re.exec(mail);
  if(RegExp.$3!="" && RegExp.$3!="." && RegExp.$2!=".")
		strr = RegExp.$1+RegExp.$2+RegExp.$3;
  else
	if(RegExp.$2!="" && RegExp.$2!=".")
		strr = RegExp.$1+RegExp.$2;
	else
		strr = RegExp.$1;
	
	return (strr==mail);
};

String.prototype.toJSON = function  () {
	return Ext.util.JSON.decode(decodeURI(this));
};

String.prototype.isPhone = function () {
	var re=  /^[\d\(\)\+\-#\*]*\d[\d\(\)\+\-#\*]*$/;
	return re.test(this.trim());
};

String.prototype.isDate = function () {
	var reg = /^(\d{4})([\/,-])(\d{1,2})\2(\d{1,2})$/;
	var r = this.match(reg);
	if(r==null) return false;
	var d= new Date(r[1], r[3]-1,r[4]);
	var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate();
	date=r[1]+r[2]+((r[3]-1)+1)+r[2]+((r[4]-1)+1);
	return newStr==date;
};

String.prototype.isMobilePhone = function(){
	if (this.trim().search(/^[0-9 | -]*$/)==-1) {// /^((13|15|18)\d{9})$/
		return false;
	} else {
		return true;
	}
};

String.prototype.ltrim = function() {
	return this.replace(/^\s*/,"");
};

String.prototype.rtrim = function() {
	return this.replace(/\s*$/,"");
};

String.prototype.trim  = function() {
	return this.ltrim().rtrim();
};

String.prototype.toDateString = function (pattern){
	return dateFormat(this.toString(), (!pattern) ? "yyyy/mm/dd" : pattern);
};

String.prototype.replaceAll  = function(s1,s2){   
	return this.replace(new RegExp(s1,"gm"),s2);   
};

Date.prototype.string = function (pattern){ 
	return dateFormat(this, (!pattern) ? "yyyy/mm/dd" : pattern);	
};

String.prototype.isNull = function(){
	if (this == null || this.trim()== "") {
		return true;
	} else {
		return false;
	}
};